#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/5/6 14:48
# @Author : 闫峰
# @File    : get_all_files_path.py
import os


def get_all_files(file_path, yaml_data_switch=False) -> list:
    """
    获取文件路径
    :param file_path: 目录路径
    :param yaml_data_switch: 是否过滤文件为 yaml格式， True则过滤
    :return:
    """
    filename = []
    # 获取所有文件下的子文件名称
    for root, dirs, files in os.walk(file_path):
        for _file_path in files:
            path = os.path.join(root, _file_path)
            if yaml_data_switch:
                if 'yaml' in path or '.yml' in path:
                    filename.append(path)
            else:
                filename.append(path)
    return filename


def get_all_executefile(file_path, yaml_data_switch=False) -> list:
    """
    获取文件路径
    :param file_path: 目录路径
    :param yaml_data_switch: 是否过滤文件为 yaml格式， True则过滤
    :return:
    """
    filename = []
    # 获取所有文件下的子文件名称
    for root, dirs, files in os.walk(file_path):
        for _file_path in files:
            path = os.path.join(root, _file_path)
            if yaml_data_switch:
                if path.endswith(".py"):
                    # if path.split("\\")[-1] != 'conftest.py' or path.split("\\")[-1] != '__init__.py':
                    filename.append(path)
            else:
                filename.append(path)

    # filename.remove(ensure_path_sep("\\test_case\\conftest.py"))
    # filename.remove(ensure_path_sep("\\test_case\\__init__.py"))

    return filename
#
#
# if __name__ == '__main__':
#     print(get_all_executefile(r"D:\zhcx-api-auto\test_case",yaml_data_switch=True))
